home *** CD-ROM | disk | FTP | other *** search
- /* RegMenu.c
- * Handle the Registration menu in Writeswell Jr.
- * Copyright ©1993 Working Software, Inc. All Rights Reserved.
- * 8 Mar 93 Mike Crawford
- */
-
- #include "TBConstants.h"
- #include "TBGlobals.h"
- #include "RegMenu.h"
- #include "WWJrAbout.h"
- #include "OutlineButton.h"
- #include "PrintWWJr.h"
- #include "MyFiles.h"
- #include "MyTextEdit.h"
-
- void InstallVersionText( DialogPtr dlg, short item );
- void PrintRegCard( StringPtr addrStr );
- void SaveRegCard( StringPtr addrStr );
- OSErr CreateRegWindow( StringPtr addrStr );
- void GetVersionString( StringPtr versStr );
-
- Boolean DoRegMenu( short theItem )
- {
- switch( theItem ){
- case kRMAboutMe:
- DoAboutMe();
- break;
- case kRMRegister:
- RegisterForm();
- break;
- default:
- break;
- }
-
- return true;
- }
-
- void RegisterForm( void )
- {
- DialogPtr dlg;
- short item;
- short curFile;
- Handle h;
- short kind;
- Rect r;
- Boolean dialogDone;
- Str255 addrStr;
-
- dlg = GetNewDialog( kRegDlgID, (Ptr)NULL, (WindowPtr) -1 );
-
- if ( !dlg )
- return;
-
- curFile = CurResFile();
- UseResFile( gAppFileRefNum );
-
- /* 1.1 display the version number from the 'vers' resource -
- */
-
- InstallVersionText( dlg, kRDVersionStringItem );
- SelIText( dlg, kRDTextEntryItem, 0, 32767 );
-
- dialogDone = false;
-
- do {
- ModalDialog( (ModalFilterUPP)NULL, &item );
-
- switch ( item ){
- case kRDPrintButton:
- case kRDSaveButton:
- case kRDDoneButton:
- dialogDone = true;
- break;
- default:
- break;
- }
- } while ( !dialogDone );
-
- if ( item != kRDDoneButton ){
- GetDItem( dlg, kRDTextEntryItem, &kind, &h, &r );
- GetIText( h, addrStr );
- }
-
- DisposDialog( dlg );
-
- UseResFile( curFile );
-
- switch ( item ){
- case kRDPrintButton:
- PrintRegCard( addrStr );
- break;
- case kRDSaveButton:
- SaveRegCard( addrStr );
- break;
- default:
- break;
- }
-
- return;
- }
-
- void InstallVersionText( DialogPtr dlg, short item )
- {
- short kind;
- Handle h;
- Rect r;
- Str255 versStr;
-
- GetVersionString( versStr );
-
- GetDItem( dlg, item, &kind, &h, &r );
-
- SetIText( h, versStr );
-
-
- return;
- }
-
- void GetVersionString( StringPtr versStr )
- {
- StringPtr shortVersion;
- VersRecHndl versH;
-
- versH = (VersRecHndl)Get1Resource( 'vers', rVersID );
-
- if ( !versH ){
- versStr[ 0 ] = '\0';
- return;
- }
-
- shortVersion = (*versH)->shortVersion;
-
- BlockMove( shortVersion, versStr, shortVersion[ 0 ] + 1 );
-
- return;
- }
-
- void PrintRegCard( StringPtr addrStr )
- {
- WindowPtr oldDocWindow;
- Boolean oldDocDirty;
- Boolean oldDocExists;
- ControlHandle oldVertScroll;
- short oldLinesPerPage;
-
- /* STUB handle this by supporting multiple open windows */
-
- oldDocWindow = gDocWindow;
- oldDocDirty = gDocDirty;
- oldDocExists = gDocExists;
- oldVertScroll = gVertScroll;
- oldLinesPerPage = gLinesPerPage;
-
- if ( oldDocWindow )
- HideWindow( oldDocWindow );
-
- gDocWindow = (WindowPtr)NULL;
-
- if ( !CreateRegWindow( addrStr ) ){
-
- DoPrint();
-
- }
-
- if ( gDocWindow )
- DisposeWindow( gDocWindow );
-
- gDocWindow = oldDocWindow;
- gDocDirty = oldDocDirty;
- gDocExists = oldDocExists;
- gVertScroll = oldVertScroll;
- gLinesPerPage = oldLinesPerPage;
-
- if ( gDocWindow )
- ShowWindow( gDocWindow );
-
- return;
- }
-
- void SaveRegCard( StringPtr addrStr )
- {
- WindowPtr oldDocWindow;
- Boolean oldDocDirty;
- Boolean oldDocExists;
- ControlHandle oldVertScroll;
- short oldLinesPerPage;
-
- /* STUB handle this by supporting multiple open windows */
-
- oldDocWindow = gDocWindow;
- oldDocDirty = gDocDirty;
- oldDocExists = gDocExists;
- oldVertScroll = gVertScroll;
- oldLinesPerPage = gLinesPerPage;
-
- if ( oldDocWindow )
- HideWindow( oldDocWindow );
-
- gDocWindow = (WindowPtr)NULL;
-
- if ( !CreateRegWindow( addrStr ) ){
-
- DoSave();
- DoCloseWindow();
-
- }
-
- if ( gDocWindow )
- DisposeWindow( gDocWindow );
-
- gDocWindow = oldDocWindow;
- gDocDirty = oldDocDirty;
- gDocExists = oldDocExists;
- gVertScroll = oldVertScroll;
- gLinesPerPage = oldLinesPerPage;
-
- if ( gDocWindow )
- ShowWindow( gDocWindow );
-
- return;
- }
-
- OSErr CreateRegWindow( StringPtr addrStr )
- {
- OSErr err;
- TEHandle textH;
- Handle headTextHdl;
- long headSize;
- short curFile;
- Str255 versStr;
-
- if ( err = MakeNewWindow() )
- return err;
-
- textH = GetTextHandle( gDocWindow );
-
- curFile = CurResFile();
- UseResFile( gAppFileRefNum );
-
- headTextHdl = Get1Resource( 'TEXT', kHeadTextID );
-
- if ( !headTextHdl )
- return resNotFound;
-
- headSize = GetHandleSize( headTextHdl );
-
- HLock( headTextHdl );
-
- TEInsert( *headTextHdl, headSize, textH );
-
- HUnlock( headTextHdl );
- ReleaseResource( headTextHdl );
-
- GetVersionString( versStr );
- TEInsert( &versStr[ 1 ], (long)versStr[ 0 ], textH );
-
- TEInsert( "\015", 1, textH );
-
- TEInsert( &addrStr[ 1 ], (long)addrStr[ 0 ], textH );
-
- return noErr;
- }
-